export const setToken = (val: string) => {
  localStorage.setItem("token", val);
};

export const getToken = () => {
  return localStorage.getItem("token");
};

export const rememberPwd = (username: string, password: string) => {
  localStorage.setItem(
    "remember",
    JSON.stringify({ username: username, password: password })
  );
};

export const getRemember = (): {
  username: string;
  password: string;
} | null => {
  const res = localStorage.getItem("remember");
  return res ? JSON.parse(res) : null;
};

export const clearRemember = () => {
  localStorage.removeItem("remember");
};
export const getUserInfo = () => {
  const res = localStorage.getItem("userInfo");
  return res ? JSON.parse(res) : null;
};

export const setUserInfo = (data: any) => {
  localStorage.setItem("userInfo", JSON.stringify(data));
};
export const setStoreId = (id: string) => {
  localStorage.setItem("storeId", id);
};
export const getStoreId = () => {
  return localStorage.getItem("storeId");
};

export default {
  setToken,
  getToken,
};
